package top.maohh.study.redis.listen;

import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.stereotype.Component;
import top.maohh.study.redis.entity.Person;

/**
 * zookeeper事件监听
 *
 * @author maohh
 */
@Component
@Slf4j
public class RedisListen {
    public void getMessage(String object) {
        log.info(object);
        Jackson2JsonRedisSerializer serializer = new Jackson2JsonRedisSerializer(Person.class);
        ObjectMapper objectMapper = new ObjectMapper();
        objectMapper.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
        objectMapper.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
        serializer.setObjectMapper(objectMapper);
        Person user = (Person) serializer.deserialize(object.getBytes());
        System.out.println("消息客户端收到：" + user.toString());
    }
}
